#include <stdio.h>
#include "libtspl.h"


/**
 * @brief 佳博打印机传入参数
 * 运行命令和参数说明
 * ./testsdk ipaddress SIZE1 SIZE2 GAP1 GAP2 DIRECTION BMPcoordinate1 BMPcoordinate2
 * @param argc 
 * @param argv 
 * @return int 
 */
int main(int argc, char *argv[])
{
    // 检查是否有足够的命令行参数
     if (argc < 1) {
        printf("Usage: %s <argument>\n", argv[0]);
        return 1;
    }

    // // 打印所有提供的命令行参数
    // for (int i = 1; i < argc; i++) {
    //     printf("Argument %d: %s\n", i, argv[i]);
    // }

    int result;
    int status;
    char commandString[100]; // 确保这个数组足够大以存储完整的命令字符串


    // result = openport("USB");
    // result = openport("ttyS1");
    result = openethernet(argv[1], 9100); //ip 192.168.1.100

    if(!result)
    {
        printf("Error: can't open printer.\n");
        return -1;
    }

    status = printerstatus();
    if(status != 0)
    {
        printf("Error: printer is not ready. status=0x%x\n", status);
        return -1;
    }

    printf("Printer Status: 0x%x\n", status);

    // printf("name: %s\n", printername());

    // result = sendcommand("SIZE 76 mm, 80 mm");
    sprintf(commandString, "SIZE %s mm, %s mm", argv[2], argv[3]);
    result = sendcommand(commandString);

    if(!result)
    {
        printf("Error: can't send command to printer.\n");
        closeport();
        return -1;
    }

    // GAP 2 间隙纸
    sprintf(commandString, "GAP %s mm, %s mm", argv[4], argv[5]);
    sendcommand(commandString);
        // sendcommand("GAP 2 mm, 0 mm");
    // GAP 0 连续纸
    // sendcommand("GAP 0 mm, 0 mm");

    sendcommand("SPEED 4");
    sendcommand("DENSITY 8");

    sprintf(commandString,"DIRECTION %s", argv[6]);
    sendcommand(commandString);
        // sendcommand("DIRECTION 1");
    clearbuffer();
    // barcode("100", "150", "128", "100", "1", "0", "2", "2", "Barcode Test");
    // printerfont("100", "300", "3", "0", "1", "1", "Print Font Test");
    // windowsfont(100, 50, 40, 0, "ARIALUNI.TTF", "にっぽんごEnglish中文한글");
    // downloadpcx("UL.PCX", "UL.PCX");
    // sendcommand("PUTPCX 100,400,\"UL.PCX\"");
    sendcommand("KILL \"*\"");
    sendcommand("KILL F,\"*\"");
    downloadpcx("1.bmp", "1.bmp");
    sprintf(commandString,"PUTBMP %s,%s,\"1.bmp\"",argv[7],argv[8]);//10,200
    sendcommand(commandString);
    printlabel("1", "1");

    // closeport(); 
    printf("TSPL.cpp Printing finished.\n");
    return 0;
}

//  g++ testsdk.cpp -o testsdk -ltspl;./testsdk
